import { Message } from 'element-ui'

const success = (data) => {
  Message({
    type: 'success',
    showClose: true,
    duration: '3000',
    message: data || '操作成功'
  })
}

const error = (data) => {
  Message({
    type: 'error',
    showClose: true,
    duration: '3000',
    message: data || '操作失败'
  })
}

const warning = (data) => {
  Message({
    type: 'warning',
    showClose: true,
    duration: '3000',
    message: data || '警告信息'
  })
}

const basic = (data) => {
  Message({
    showClose: true,
    duration: '3000',
    message: data || '提示信息'
  })
}

const declareUp = (data) => {
  let parse = JSON.parse(data)
  let errormsg = '操作失败 <br/>'
  for (let i = 0; i <= parse.length; i++) {
    if (parse[i].contractName == null) {
      errormsg = '项目：' + parse[i].projectName + '- 合同为空'
      Message({
        type: 'error',
        showClose: true,
        duration: '3000',
        message: errormsg
      })
      return errormsg
    }
    if (parse[i].service_pre_amount == null) {
      errormsg = '合同：' + parse[i].contractName + '- 下资产请添加并补全字段'
      Message({
        type: 'error',
        showClose: true,
        duration: '3000',
        message: errormsg
      })
      return errormsg
    }
    if (parse[i].targetDesc == null) {
      errormsg =
        '合同：' + parse[i].contractName + '- 招标技术参数为空'
      Message({
        type: 'error',
        showClose: true,
        duration: '3000',
        message: errormsg
      })
      return errormsg
    }
  }
}
export default {
  success,
  error,
  warning,
  basic,
  declareUp
}